import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);


const store = new Vuex.Store({
	state: {
		currentUser: uni.getStorageSync('currentUser') || {},
		adminData: uni.getStorageSync('adminData') || [{
			identity: 2,
			account: 'admin',
			password: 'admin'
		}],
		userManagement: uni.getStorageSync('userManagement') || [{
			name: '张三',
			age: '21',
			sex: 0,
			mobilePhone: '13654987621',
			IDNumber: '432169875164321469',
			email: '1264973168@qq.com',
			identity: 0,
			account: 'user',
			password: 'user'
		}, {
			name: '李斯',
			age: '26',
			sex: 1,
			mobilePhone: '13654987621',
			IDNumber: '416597651369871666',
			email: '2649873165@qq.com',
			identity: 0,
			account: 'user1',
			password: 'user1'
		}],
		doctorManagement: uni.getStorageSync('doctorManagement') || [{
			name: '张明智',
			age: '32',
			identity: 1,
			account: 'doctor',
			password: 'doctor',
			sex: 0,
			mobilePhone: '13649854624',
			IDNumber: '436985165948513216',
			email: '123156',
			great: '内科',
			introduction: '内科医生'
		}],
		evaluateData: uni.getStorageSync('evaluateData') || []
	},
	mutations: {
		getLogin(state, data) {
			state.currentUser = data
			uni.setStorageSync('currentUser', data)
		},
		addUserData(state, data) {
			state.userManagement.push(data)
			uni.setStorageSync('userManagement', data)
		},
		addDoctorManagement(state, data) {
			state.doctorManagement.push(data)
			uni.setStorageSync('doctorManagement', data)
		},
		addEvaluateData(state, data) {
			state.evaluateData.unshift(JSON.parse(JSON.stringify(data)))
			// state.evaluateData = [data, ...state.evaluateData]
			uni.setStorageSync('evaluateData', data)
		},
		setUserData(state, data) {
			state.userManagement = data
			uni.setStorageSync('userManagement', data)
		},
		setDoctorManagement(state, data) {
			state.doctorManagement = data
			uni.setStorageSync('doctorManagement', data)
		}
	}
})

export default store
